<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
<!--    导入自己的css文件-->
    <link rel="stylesheet" href="../css/my-css.css">
</head>
<body>
<div id="app">
    <el-container>
        <my-header></my-header>
        <el-main
                style="background-image: url('../img/usermodel/bg.jpg');
                background-size: cover;height: 650px">
            <el-card style="width: 500px;height: 300px;margin: 100px 200px 0px 750px">
                <el-form label-width="80px" style="width: 400px;margin: 50px auto">
                    <el-form-item label="用户名">
                        <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-input type="password" placeholder="请输入用密码" v-model="user.password"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="login">登录</el-button>
                    </el-form-item>
                    <a href="/usermodel/reg.html" style="position: relative;left: 360px;
                        text-decoration: none;color: #666666;font-size: 14px">
                        立即注册
                    </a>
                </el-form>
            </el-card>
        </el-main>
        <my-footer></my-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入axios框架文件-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<!--导入自己的头部js文件-->
<script src="../js/my-header.js"></script>
<!--导入自己的尾部js文件-->
<script src="../js/my-footer.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user:{
                    username:"test",
                    password:"123"
                }
            }
        },
        methods: {
            login(){
                axios.post("/v1/users/login",v.user).then(response => {
                    if (response.data.code==20000){
                        //登录成功后将用户信息保存到localStorage中
                        localStorage.user = JSON.stringify(response.data.data);
                        location.href='/usermodel/index.html'
                    }else {
                        v.$message.error(response.data.message)
                    }
                })
            }
        },
        created(){
            localStorage.clear();
        }
    })
</script>
</html>